package com.zhuss.vent.processor;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.SearchKeyWordBo;
import com.zhuss.bean.bo.vent.vent.SearchVentBo;
import com.zhuss.bean.bo.vent.vent.wechat.ListVentBo;
import com.zhuss.bean.vo.DetailKeyWordVo;
import com.zhuss.bean.vo.vent.vent.DetailVentVo;
import com.zhuss.bean.vo.vent.vent.ListVentVo;
import com.zhuss.vent.db.dao.ext.VentDao;
import com.zhuss.vent.db.entity.Vent;
import com.zhuss.common.PageVo;
import com.zhuss.exception.ExceptionCode;
import com.zhuss.exception.WpsException;


/**
 * 查询匿名吐槽 processor
 * @Author: zhushanshuo
 * @Date: 2019/9/24 19:54
 */
@Component("ventRead")
public class VentRead {
	
	@Autowired
	private VentDao ventDao;
	
	/**
	 * 匿名吐槽 
	 * @return
	 */
	public Object listVentId(Integer area) {
		List<Vent> ventList = ventDao.listAll(area);
		List<Long> result = new ArrayList<>();
		transferListId(ventList, result);
		return result;
	}
	
	/**
	 * keyWord
	 * @param bo
	 * @return
	 */
	public PageVo<DetailKeyWordVo> keyWord(SearchKeyWordBo bo) {
		PageVo<DetailKeyWordVo> result = new PageVo<DetailKeyWordVo>();
		List<DetailKeyWordVo> list = new ArrayList<DetailKeyWordVo>();
		list = ventDao.keyWord(bo);
		Integer count = ventDao.countKeyWord(bo);
		result.setPageNum(bo.getPageNum());
		result.setPageSize(bo.getPageSize());
		result.setTotal(count);
		result.setItems(list);
		return result;
	}
	
	
	
	/**
	 * 匿名吐槽列表
	 * @param bo
	 * @return
	 */
	public Object listVent(ListVentBo bo) {
		PageVo<DetailVentVo> result = new PageVo<DetailVentVo>();
		List<DetailVentVo> list = new ArrayList<DetailVentVo>();
		list = ventDao.listVent(bo);
		Integer count = ventDao.countVentList(bo);
		result.setPageNum(bo.getPageNum());
		result.setPageSize(bo.getPageSize());
		result.setTotal(count);
		result.setItems(list);
		return result;
	}
	
	private void transferListId(List<Vent> ventList, List<Long> result) {
		for (Vent item : ventList) {
			result.add(item.getVentId());
		}
	}

	/**
	 * 匿名吐槽列表
	 * @param bo
	 * @return
	 */
	public Object list(SearchVentBo bo) {
		PageVo<ListVentVo> result = new PageVo<ListVentVo>();
        result.setPageNum(bo.getPageNum());
        result.setPageSize(bo.getPageSize());
        result.setItems(ventDao.list(bo));
        result.setTotal(ventDao.countList(bo));
		return result;
	}
	
	/**
	 * 匿名吐槽详情
	 * @param ventId
	 * @return
	 * @throws WpsException
	 */
	public Object detail(Long ventId) throws WpsException {
		Object result = ventDao.detail(ventId);
		if (result == null) {
			throw new WpsException(ExceptionCode.数据不存在);
		}
		return result;
	}
	
	

}
